import time

from appium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as es
from time import sleep


class test_01():

    def __init__(self):
        cap={
            "platformName": "Android",
            "appium:deviceName": "emulator-5554",
            "appPackage": "com.kongfz.app",
            "appActivity": "com.kongfz.app.home.mvvm.homepage.HomeActivity",
            "noReset":True
        }


        self.dr=webdriver.Remote("http://127.0.0.1:4723/wd/hub",cap)

        self.dr.implicitly_wait(70)

        sleep(40)


    def loc1(self,loc):
        try:
            return self.dr.find_element(*loc)
        except Exception as e:
            print("未找到元素",loc)

    def loc2(self, loc):
        try:
            return self.dr.find_element_by_android_uiautomator(loc)
        except Exception as e:
            print("未找到元素", loc)

    def loc3(self, loc):
        try:
            return WebDriverWait(self.dr,10).until(es.presence_of_element_located(loc))
        except Exception as e:
            print("未找到元素", loc)

    def loc4(self,filep):
        t=time.strftime("%Y%m%d%H%M%S")

        self.dr.save_screenshot(t+filep)


    def loc5(self, loc,key):
        if type(loc)==str:
            ele=self.loc2(loc)
        else:
            ele=self.loc1(loc)


            return ele.get_attribute(key)

    def loc6(self):
        self.dr.quit()
        

